﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SYH.Utils;
namespace syh876.com.Controllers
{
    public class CheckCodeController : Controller
    {
        //
        // GET: /CheckCode/

        /// <summary>
        /// 生成图片验证码
        /// </summary>
        /// <returns></returns>
        public ActionResult CreateCodeImg()
        {
            CheckCodeHelper checkCodeHelper = new CheckCodeHelper();
            string checkCode = checkCodeHelper.CreateRandomCode(5);
            Session["CheckCode"] = checkCode;
            byte[] by = checkCodeHelper.CreateImage(checkCode);
            return File(by, @"image/jpeg");
        }

        /// <summary>
        /// 校验验证码
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public ActionResult CheckCode(string code)
        {
            string s_checkCode = string.Empty;
            if (Session["CheckCode"] != null)
                s_checkCode = Session["CheckCode"].ToString();    
            return View();
        }

        /// <summary>
        /// 手机发送验证码
        /// </summary>
        /// <param name="telPhone"></param>
        /// <param name="operatin"></param>
        /// <returns></returns>
        public ActionResult SendSms(string telPhone, string operatin)
        {
            //随机生成4位数字验证吗
            CheckCodeHelper checkCode = new CheckCodeHelper();
            string SmsCode = SYH.Utils.CheckCodeHelper.RandomCode(4);
            Session["SmsCode"] = SmsCode;

            //发送短信
            SYH.Utils.SMS.SendSms send = new SYH.Utils.SMS.SendSms(telPhone, SmsCode, operatin, "生意汇");
            string msg = send.SmsSendCode();

            return Content(msg);
        }

      
    }
}
